﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Text;
using System.IO;

public partial class Bulksms : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            customers.DataSource = SqlDataSource1;
            customers.DataBind();
        }
    }
    protected void send_Click(object sender, EventArgs e)
    {
        string result;
        try
        {
            foreach (ListItem item in customers.Items)
            {
                if(item.Selected)
                {
                string data = "";
                data += "username=" + HttpUtility.UrlEncode("smaa", System.Text.Encoding.GetEncoding("ISO-8859-1"));
                data += "&password=" + HttpUtility.UrlEncode("3080156", System.Text.Encoding.GetEncoding("ISO-8859-1"));
                data += "&message=" + HttpUtility.UrlEncode(TextBox1.Text, System.Text.Encoding.GetEncoding("ISO-8859-1"));
                data += "&want_report=1";
                data += "&msisdn="+item.Value;

                byte[] buffer = Encoding.Default.GetBytes(data);
                HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://bulksms.vsms.net:5567/eapi/submission/send_sms/2/2.0");
                WebReq.Method = "POST";
                WebReq.ContentType = "application/x-www-form-urlencoded";
                WebReq.ContentLength = buffer.Length;
                Stream PostData = WebReq.GetRequestStream();

                PostData.Write(buffer, 0, buffer.Length);
                PostData.Close();

                HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
                Console.WriteLine(WebResp.StatusCode);

                Stream Response = WebResp.GetResponseStream();
                StreamReader _Response = new StreamReader(Response);
                result = _Response.ReadToEnd();
                Label1.Text = result;
                }
            }
        }
        catch (Exception ex)
        {
            Label1.Text=ex.Message;
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        foreach (ListItem ll in customers.Items)
        {
            ll.Selected = true;
        
        }
    }
  
    
}
